'''
Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
Date: 2025-02-27 09:34:31
LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
LastEditTime: 2025-02-27 12:34:44
FilePath: \收藏夹整理\main.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
#!/usr/bin/env python3
"""
书签导航门户生成器主程序
"""

import click
from pathlib import Path
from rich.console import Console
from rich.progress import Progress
from bookmark_parser.parser import BookmarkParser
from portal_generator.generator import PortalGenerator

console = Console()

@click.command()
@click.option('--input', '-i', required=True, help='输入的书签HTML文件路径')
@click.option('--output', '-o', default='output', help='输出目录路径')
@click.option('--template', '-t', default='templates', help='模板目录路径')
@click.option('--title', '-T', default='收藏夹导航', help='网站标题')
def main(input: str, output: str, template: str, title: str):
    """生成书签导航门户网站"""
    
    try:
        # 解析书签文件
        with Progress() as progress:
            task = progress.add_task("[cyan]解析书签文件...", total=1)
            
            # 读取HTML文件
            with open(input, 'r', encoding='utf-8') as f:
                html_content = f.read()
            
            parser = BookmarkParser()
            root_category = parser.parse(html_content)
            
            progress.update(task, advance=1)
            
        # 生成网站
        with Progress() as progress:
            task = progress.add_task("[green]生成网站文件...", total=1)
            
            generator = PortalGenerator(output, template)
            generator.generate(root_category, title=title)
            
            progress.update(task, advance=1)
            
        console.print("[bold green]✓[/] 网站生成完成!")
        console.print(f"[bold]输出目录:[/] {Path(output).absolute()}")
        
    except Exception as e:
        console.print(f"[bold red]错误:[/] {str(e)}")
        raise click.Abort()
        
if __name__ == '__main__':
    main() 